package com.ruoyi.web.controller.bill;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BillLable;
import com.ruoyi.system.service.IBillLableService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 账单标签Controller
 * 
 * @author ruoyi
 * @date 2023-03-17
 */
@Controller
@RequestMapping("/bill/lable")
public class BillLableController extends BaseController
{
    private String prefix = "bill/lable";

    @Autowired
    private IBillLableService billLableService;

    @RequiresPermissions("bill:lable:view")
    @GetMapping()
    public String lable()
    {
        return prefix + "/lable";
    }

    /**
     * 查询账单标签列表
     */
    @RequiresPermissions("bill:lable:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BillLable billLable)
    {
        startPage();
        List<BillLable> list = billLableService.selectBillLableList(billLable);
        return getDataTable(list);
    }

    /**
     * 导出账单标签列表
     */
    @RequiresPermissions("bill:lable:export")
    @Log(title = "账单标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BillLable billLable)
    {
        List<BillLable> list = billLableService.selectBillLableList(billLable);
        ExcelUtil<BillLable> util = new ExcelUtil<BillLable>(BillLable.class);
        return util.exportExcel(list, "账单标签数据");
    }

    /**
     * 新增账单标签
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存账单标签
     */
    @RequiresPermissions("bill:lable:add")
    @Log(title = "账单标签", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BillLable billLable)
    {
        return toAjax(billLableService.insertBillLable(billLable));
    }

    /**
     * 修改账单标签
     */
    @RequiresPermissions("bill:lable:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BillLable billLable = billLableService.selectBillLableById(id);
        mmap.put("billLable", billLable);
        return prefix + "/edit";
    }

    /**
     * 修改保存账单标签
     */
    @RequiresPermissions("bill:lable:edit")
    @Log(title = "账单标签", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BillLable billLable)
    {
        return toAjax(billLableService.updateBillLable(billLable));
    }

    /**
     * 删除账单标签
     */
    @RequiresPermissions("bill:lable:remove")
    @Log(title = "账单标签", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(billLableService.deleteBillLableByIds(ids));
    }
}
